<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
<button type="button" class="button">登录</button><br>
<div class="response" style="width: 200px;height:200px;border: 1px solid #3333;"></div>
<span class="span">登录ing</span>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
    $(".button").click(function(){
        $.ajax({
            url: "http://localhost:8080/auth",
            type: "GET",
            success: function(data, textStatus, xhr){
                //$(".response").text(data);
                $(".span").text("登录成功");
            },
            error: function(xhr, textStatus, errorThrown){
                if(xhr.status == 401){
                    // 当状态码为401时，从响应体中获取跳转地址
                    var redirectUrl = xhr.responseText;
                    if(redirectUrl) {
                        window.location.href = redirectUrl;
                    }
                } else {
                    $(".response").text("Error: " + textStatus);
                }
            }
        });
    });
</script>
</body>
</html>
